package com.example.understand_compose1.testcase_data.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.understand_compose1.R
import com.example.understand_compose1.testcase_data.model.MessageData

/**
 * // MessagesAdapter.java
 * public class MessagesAdapter extends RecyclerView.Adapter<MessagesAdapter.ViewHolder> {
 *     private List<Message> messages;
 *
 *     public MessagesAdapter(List<Message> messages) {
 *         this.messages = messages;
 *     }
 *
 *     @Override
 *     public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
 *         View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message, parent, false);
 *         return new ViewHolder(view);
 *     }
 *
 *     @Override
 *     public void onBindViewHolder(ViewHolder holder, int position) {
 *         Message message = messages.get(position);
 *         holder.bind(message);
 *     }
 *
 *     @Override
 *     public int getItemCount() {
 *         return messages.size();
 *     }
 *
 *     public static class ViewHolder extends RecyclerView.ViewHolder {
 *         public ViewHolder(View itemView) {
 *             super(itemView);
 *         }
 *
 *         public void bind(Message message) {
 *             // Set the message text and handle the layout based on if it's sent or received
 *         }
 *     }
 * }
 *
 */


class MessagesAdapter(messages: List<MessageData>):
    RecyclerView.Adapter<MessagesAdapter.ViewHolder>() {

    private val _messages: List<MessageData> = emptyList()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view: View = LayoutInflater
            .from(parent.context)
            .inflate(R.layout.item_message, parent, false)

        return ViewHolder(view)
    }


    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val msg: MessageData = _messages.get(position)
        holder.bind(msg)
    }

    override fun getItemCount(): Int {
        return _messages.size
    }

    // inner class
    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        fun bind(message: MessageData) {

        }
    }
}